package net.huashitong.supervision.gongjian.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.supervision.gongjian.entity.ProjectTaskEntity;
import net.huashitong.supervision.gongjian.filter.ProjectTaskFilter;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class ProjectTaskDao extends StringDao<ProjectTaskEntity> {


    /**
     * 获取数量 带分页
     * @param filter
     * @return
     */
    public List<ProjectTaskEntity> getList(ProjectTaskFilter filter){

        GenericQuery query = createQuery("obj");
        if(StringUtils.isNotBlank(filter.getProjectId()))
        {

            query.append(" and obj.projectId=:projectId").setParam("projectId",filter.getProjectId());
        }
        if(2!=filter.getValid())
        {//等于2的时候 查看有效和无效的任务
            query.append(" and obj.valid=:valid").setParam("valid",filter.getValid());

        }

        return query.listResult(filter);

    }


    public List<ProjectTaskEntity> getListNoPage(ProjectTaskFilter filter)
    {
        GenericQuery query = createQuery("obj");
        if(StringUtils.isNotBlank(filter.getProjectId()))
        {

            query.append(" and obj.projectId=:projectId").setParam("projectId",filter.getProjectId());
        }
        if(2!=filter.getValid())
        {//等于2的时候 查看有效和无效的任务
            query.append(" and obj.valid=:valid").setParam("valid",filter.getValid());
        }
        if(0!=filter.getProjectType())
        {
            query.append(" and obj.projectType=:projectType").setParam("projectType",filter.getProjectType());

        }
        return query.listResult();
    }

}
